package com.project.exception;

import com.alibaba.fastjson.JSON;
import com.project.common.Result;
import com.project.utils.WebUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response,
                         AuthenticationException authException) {

        String json = JSON.toJSONString(Result.error("认证失败.."));
        WebUtils.renderString(response,json);
    }
}